home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
powervww
/
pvinput.cpp
< prev
next >
Wrap
Text File
|
1998-01-05
|
20KB
|
887 lines
// ____________________________________________________
// | |
// | Project: POWER VIEW INTERFACE |
// | File: PVINPUT.CPP |
// | Compiler: WPP386 (10.6) |
// | |
// | Subject: Input box implementation |
// | |
// | Author: Emil Dotchevski |
// |____________________________________________________|
//
// E-mail: zajo@geocities.com
// URL: http://www.geocities.com/SiliconValley/Bay/3577
#define uses_stdio
#define uses_math
#define uses_string
#define uses_basics
#define uses_dc
#define uses_dialog
#define uses_hist
#define uses_icons
#define uses_input
#define uses_lines
#define uses_stddlg
#define uses_system
#include "PVuses.h"
//Tinput_editor publics:
Tinput_editor::Tinput_editor( char *_line, int _max_len, int _xl ):
Tmemo( _line, _max_len+1, _xl, 1 )
{
~text_editor->valid_chars;
for( int i = 32; i < 256; i++ )
text_editor->valid_chars << i;
left_icon = NEW( Ticon( "|i", cmLEFT_ARROW, 0 ) );
left_icon->set_flags( bfREPEAT, 1 );
left_icon-> set_state( isHIDDEN, 1 );
put_in( left_icon, -1, 0 );
right_icon = NEW( Ticon( "|i", cmRIGHT_ARROW, 0 ) );
right_icon->set_flags( bfREPEAT, 1 );
put_in( right_icon, xl, 0 );
right_icon->set_state( isHIDDEN, 1 );
}
void Tinput_editor::scroll_to( int _x, int _y )
{
int l;
l = text_editor->buf_len - _x;
if( l < xl - 1 )
{
_x += l - xl + 1;
if( _x < 0 ) _x = 0;
}
Teditor::scroll_to( _x, _y );
}
//Tinput_editor protected:
void Tinput_editor::get_focused( void )
{
text_editor->set_select( 0, text_editor->buf_len, 1 );
}
#ifndef HGR
void Tinput_editor::set_palette( void )
{
Teditor::set_palette();
if( !graph_flag )
{
text_attr = rolb( text_attr, 4 );
bold_attr &= 0x0F;
bold_attr |= (char) ( text_attr & 0xF0 );
}
}
#endif
void Tinput_editor::event_handler( Tevent &ev )
{
Teditor::event_handler( ev );
if( state( isFOCUSED ) && ( ev.code == evCOMMAND ) )
{
switch( ev.CMD_CODE )
{
case cmLEFT_ARROW:
scroll_to( delta_x - 1, 1 ); break;
case cmRIGHT_ARROW:
scroll_to( delta_x + 1, 1 ); break;
default:
goto hot;
}
redraw();
handled( ev );
}
hot:
left_icon->set_state( isHIDDEN, !delta_x );
right_icon->set_state( isHIDDEN, ( text_editor->buf_len - delta_x ) < xl );
if( item_acted == this ) item_acted = owner;
}
void Tinput_editor::convert_event( Tevent &ev )
{
Tevent svd;
svd = ev;
Teditor::convert_event( ev );
if( ( ev.code == evCOMMAND ) && ( ev.CMD_CODE >= cmeLINE_UP ) &&
( ev.CMD_CODE <= cmeNEW_LINE ) ) ev = svd;
}
//Tinput publics:
Tinput::Tinput( char *_prompt, char *_line, int _max_length, int _xl ):
Tcombo_item( _prompt, _xl + 3 )
{
init( _line, _max_length, _xl );
#ifndef NOHIST
history_id = NULL;
#endif
}
#ifndef NOHIST
Tinput::Tinput( char *_prompt, char *_line, int _max_length, int _xl, Tlb_list *_hist ):
Tcombo_item( _prompt, _xl + 3, _hist )
{
init( _line, _max_length, _xl );
put_in( NEW( Thistory( _hist ) ), xl, 0 );
}
#endif
void Tinput::set_data( uint i )
{
char s[256];
gettxt( i, s );
set_txt( s );
}
void Tinput::get_data( char *s )
{
editor->text_editor->get_line_str( s, editor->text_editor->buf_len );
}
void Tinput::set_txt( char *s )
{
char tmp[256];
strcpy( tmp, s );
if( strlen( tmp ) > editor->text_editor->buf_size ) tmp[editor->text_editor->buf_size] = 0;
editor->text_editor->set_select( 0, editor->text_editor->buf_len, 1 );
editor->text_editor->insert_string( tmp, 0 );
redraw();
item_acted = this;
}
void Tinput::get_txt( char *s )
{
editor->text_editor->get_line_str( s, editor->text_editor->buf_len );
}
//Tinput protected:
void Tinput::draw( void )
{
#ifndef HGR
if( !graph_flag )
{
selected_attr = rolb( selected_attr, 4 );
text_attr = rolb( text_attr, 4 );
txtf( "|%c%s|r%c %s", state(isDISABLED)?'d':'t', i_left_line, xl - 2, i_right_line );
return;
}
#endif
txtf( "%s|r%c %s", i_left_line, xl - 2, i_right_line );
}
void Tinput::get_focused( void )
{
editor->text_editor->set_select( 0, editor->text_editor->buf_len, 1 );
}
boolean Tinput::release_focus( void )
{
if( Tcombo_item::release_focus() )
{
editor->text_editor->hide_select();
return 1;
}
return 0;
}
//Tinput private:
void Tinput::init( char *_line, int _max_length, int _xl )
{
editor = NEW( Tinput_editor( _line, _max_length, _xl + 1 ) );
put_in( editor, 1, 0 );
put_in( NEW( Tline0( xl ) ), x, 1 );
put_in( NEW( Tline1( xl ) ), x, -1 );
}
//Tlinput publics:
Tlinput::Tlinput ( char *_prompt, long &_data, long _min, long _max ):
Tinput( _prompt, lin, len, init_len( _min, _max ) )
{
init( _data, _min, _max );
}
#ifndef NOHIST
Tlinput::Tlinput( char *_prompt, long &_data, long _min, long _max, Tlb_list *_hist ):
Tinput( _prompt, lin, len, init_len( _min, _max ), _hist )
{
init( _data, _min, _max );
}
#endif
boolean Tlinput::valid( uint stop_st )
{
long v;
char line[256], *end_ptr;
Tcombo_item::valid( stop_st );
if( stop_st == cmCANCEL ) return 1;
get_txt( line );
v = strtol( line, &end_ptr, hex?16:10 );
if( (!v && *end_ptr) || v<min || v>max )
{
#ifdef CYR
sprintf( line, "æ▓«⌐¡«▒▓▓á ¡Ñ Ñ ó὿ñ¡á.\n\n┐ ó║óÑñÑ▓Ñ ñ░│ú« ╢┐½« ╖¿▒½« ¼Ñªñ│ %%l%c ¿ %%l%c ", hex?'x':'d', hex?'x':'d' );
#else
sprintf( line, "Value not within the valid range.\n\nPlease enter new integer value between %%l%c and %%l%c ", hex?'x':'d', hex?'x':'d' );
#endif
focus(); _terror();
ok( line, min, max );
return 0;
}
*data = v;
return 1;
}
void Tlinput::set_num( long n )
{
char s[256];
n = maxl( n, min );
n = minl( n, max );
ltoa( n, s, hex?16:10 );
set_txt( s );
}
long Tlinput::get_num( void )
{
char s[256];
get_txt( s );
return atol( s );
}
//Tlinput private:
char Tlinput::init_len( long _min, long _max )
{
hex = __hexnum();
ltoa( _min, lin, hex?16:10 ); len = (char) strlen( lin );
ltoa( _max, lin, hex?16:10 ); if( strlen( lin ) > len ) len = (char) strlen( lin );
return len;
}
void Tlinput::init( long &_data, long _min, long _max )
{
ltoa( _data, lin, hex?16:10 );
set_txt( lin );
data = &_data; min = _min; max = _max;
~editor->text_editor->valid_chars;
editor->text_editor->valid_chars << '-';
for( int i = '0'; i <= '9'; i++ )
editor->text_editor->valid_chars << i;
if( hex )
{
for( i = 'A'; i <= 'F'; i++ )
editor->text_editor->valid_chars << i;
for( i = 'a'; i <= 'f'; i++ )
editor->text_editor->valid_chars << i;
}
}
//Tiinput publics:
Tiinput::Tiinput( char *_prompt, int &_data, int _min, int _max ):
Tlinput( _prompt, tmp, _min, _max )
{
set_num( _data );
tmp = _data;
dta = &_data;
}
#ifndef NOHIST
Tiinput::Tiinput( char *_prompt, int &_data, int _min, int _max, Tlb_list *_hist ):
Tlinput( _prompt, tmp, _min, _max, _hist )
{
set_num( _data );
tmp = _data;
dta = &_data;
}
#endif
boolean Tiinput::valid( uint stop_st )
{
boolean result;
result = Tlinput::valid( stop_st );
*dta = tmp;
return result;
}
//Tsinput publics:
Tsinput::Tsinput( char *_prompt, short &_data, short _min, short _max ):
Tlinput( _prompt, tmp, _min, _max )
{
set_num( _data );
tmp = _data;
dta = &_data;
}
#ifndef NOHIST
Tsinput::Tsinput( char *_prompt, short &_data, short _min, short _max, Tlb_list *_hist ):
Tlinput( _prompt, tmp, _min, _max, _hist )
{
set_num( _data );
tmp = _data;
dta = &_data;
}
#endif
boolean Tsinput::valid( uint stop_st )
{
boolean result;
result = Tlinput::valid( stop_st );
*dta = (short) tmp;
return r